package person.bing.fbcloud.leetcode;

/**
 * @author: mengfanbing
 * @date: 2020/8/21 9:14
 */
public class Q111 {
    public static void main(String[] args) {

    }
    public static int minDepth(TreeNode root) {
        if (root == null){
            return 0;
        }
        int left = minDepth(root.left);
        int right = minDepth(root.right);
        if (root.left == null || root.right == null){
            return left + right + 1;
        }
        return Math.min(left,right) + 1;
    }



    public class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode(int x) { val = x; }
  }
}
